package com.powernode.service;


import com.powernode.dao.DormitoryAdminMapper;
import com.powernode.dao.IsolatedManMapper;
import com.powernode.pojo.DormitoryAdmin;
import com.powernode.pojo.IsolatedMan;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author Liutianci
 */
@Service
public class DormitoryAdminService {

    @Resource
    public DormitoryAdminMapper dormitoryAdminMapper;
    @Resource
    public IsolatedManMapper isolatedManMapper;

    public void modify(DormitoryAdmin doctor) {
        dormitoryAdminMapper.update(doctor);
    }

    public void add(DormitoryAdmin doctor) {
        dormitoryAdminMapper.insert(doctor);
    }

    public Integer checkIsbn(DormitoryAdmin doctor) {
        return dormitoryAdminMapper.countIsbn(doctor);
    }

    public void removes(Integer[] ids) {
        //由于三表分离，只需要考虑 寝室长被删除的时候，进行此学号的隔离者身份角色的修改，修改为： 普通
        for (int i = 0; i < ids.length; i++) {
            IsolatedMan isolatedMan = isolatedManMapper.selectByStudentNumber(dormitoryAdminMapper.select(ids[i]).getStudentNumber());
            isolatedMan.setRole("普通");
            isolatedManMapper.update(isolatedMan);
        }
        dormitoryAdminMapper.deletes(ids);
    }

    public void deletesByDocid(String[] docids) {
        dormitoryAdminMapper.deletesByStudentNumber(docids);
    }

    public DormitoryAdmin get(Integer id) {
        return dormitoryAdminMapper.select(id);
    }

    public int count(Map<String, Object> param) {
        return dormitoryAdminMapper.count(param);
    }

    public List<DormitoryAdmin> getPageResult(Map<String, Object> param) {
        return dormitoryAdminMapper.selectPageResult(param);
    }

    public DormitoryAdmin getByIsbn(String bookIsbn) {
        return dormitoryAdminMapper.selectByIsbn(bookIsbn);
    }

    public DormitoryAdmin getById(Integer id) {
        return dormitoryAdminMapper.selectById(id);
    }

    public DormitoryAdmin selectByDoctorId(String doctorId) {return dormitoryAdminMapper.selectByStudentNumber(doctorId);}

    public DormitoryAdmin selectBySite(String site) {
        return dormitoryAdminMapper.selectBySite(site);
    }
}
